package studio.raptor.ddal.dashboard.log.bo;

import lombok.Getter;
import lombok.Setter;
import studio.raptor.ddal.core.log.bo.ConnPoolLogData;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * Created by liujy on 2018/1/16.
 */
@Getter
@Setter
@Entity
@Table(name = "log_conn_pool")
public class ConnPoolLogExtendData  implements Serializable,Cloneable{

    @Id
    @Column(name = "trace_id")
    private String traceId;
    @Column(name = "poolname")
    private String poolName;
    @Column(name = "readonly")
    private String isReadOnly;
    @Column(name = "connection_timeout")
    private long connectionTimeout;
    @Column(name = "idle_timeout")
    private long idleTimeout;
    @Column(name = "jdbcurl")
    private String jdbcUrl;
    @Column(name = "dbuser")
    private String dbuser;
    @Column(name = "maxpoolsize")
    private  int maxPoolSize;
    @Column(name = "minidle")
    private  int minIdle;
    @Column(name = "total_connections")
    private int totalConnections;
    @Column(name = "idle_connections")
    private int idleConnections;
    @Column(name = "active_connections")
    private int activeConnections;
    @Column(name = "awaiting_connections")
    private int awaitingConnections;
    @Column(name = "create_time")
    private Date createTime;
    @Column(name = "accept_time")
    private Date acceptTime;
    @Column(name = "appname")
    private String appName;

    public void clone(ConnPoolLogData connPoolLogData){
        this.traceId= UUID.randomUUID().toString();
        this.poolName=connPoolLogData.getPoolName();
        this.isReadOnly=connPoolLogData.isReadOnly();
        this.connectionTimeout=connPoolLogData.getConnectionTimeout();
        this.idleTimeout=connPoolLogData.getIdleTimeout();
        this.jdbcUrl=connPoolLogData.getJdbcUrl();
        this.dbuser= connPoolLogData.getUsername();
        this.maxPoolSize=connPoolLogData.getMaxPoolSize();
        this.minIdle=connPoolLogData.getMinIdle();
        this.totalConnections=connPoolLogData.getTotalConnections();
        this.idleConnections=connPoolLogData.getIdleConnections();
        this.activeConnections=connPoolLogData.getActiveConnections();
        this.awaitingConnections=connPoolLogData.getAwaitingConnections();
        this.acceptTime=connPoolLogData.getAcceptTime();
    }
}
